from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from page_locators.addresspage_locator import AddresspageLocator as AL
from Common.base_page import BasePage

class AddressPage(BasePage):

    def __init__(self, driver):
        super().__init__(driver)


    def add_address(self,username,mobile,province,city,district,twon,address):
        # self.driver.find_element(*AL.address_link_loc).click()
        # self.driver.find_element(*AL.new_address_loc).click()
        # self.driver.find_element(*AL.consignee_loc).send_keys(username)
        # self.driver.find_element(*AL.mobile_loc).send_keys(mobile)
        # self.select_action(AL.province_loc,province)
        # self.select_action(AL.city_loc,city)
        # self.select_action(AL.district_loc,district)
        # self.select_action(AL.twon_loc,twon)
        # self.driver.find_element(*AL.address_loc).send_keys(address)
        # self.driver.find_element(*AL.save_address_loc).click()
        self.click_element(AL.address_link_loc,"地址管理模块_地址管理页面_地址管理点击操作")
        self.click_element(AL.new_address_loc,"地址管理模块_地址管理页面_新增地址操作")
        self.input_text(AL.consignee_loc,username,"地址管理模块_地址管理页面_收货人输入操作")
        self.input_text(AL.mobile_loc,mobile,"地址管理模块_地址管理页面_电话输入操作")
        self.select_action(AL.province_loc,"地址管理模块_地址管理页面_省份选择操作",visible_text=province)
        self.select_action(AL.city_loc,"地址管理模块_地址管理页面_城市选择操作",visible_text=city)
        self.select_action(AL.district_loc,"地址管理模块_地址管理页面_区域选择操作",visible_text=district)
        self.select_action(AL.twon_loc,"地址管理模块_地址管理页面_街道选择操作",visible_text=twon)
        self.input_text(AL.address_loc,address,"地址管理模块_地址管理页面_详细地址输入操作")
        self.click_element(AL.save_address_loc,"地址管理模块_地址管理页面_新增保存操作")




    # def select_action(self,loc,visible_text):
    #     select = self.driver.find_element(*loc)
    #     Select(select).select_by_visible_text(visible_text)

    def is_address_save_success(self):
        """
        验证新增地址，是否成功(收货人能否定位到)
        :return:
        """
        pass